import { BasicColumn, FormSchema } from '/@/components/Table';
import { useUserStore } from '@/store/modules/user';
import { unref } from 'vue';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '优惠券名称',
    align: 'center',
    dataIndex: 'couponName',
  },
  {
    title: '优惠券数量',
    align: 'center',
    dataIndex: 'couponAmount',
  },
  {
    title: '优惠券类型',
    align: 'center',
    dataIndex: 'couponType_dictText',
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'status_dictText',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '优惠券名称',
    field: 'couponName',
    component: 'JInput',
  },
  {
    label: '优惠券类型',
    field: 'couponType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'coupon_type',
    },
  },
];

const userStore = useUserStore();
const orgCode = unref(userStore.getUserInfo).orgCode;
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '优惠券名称',
    field: 'couponName',
    component: 'Input',
    required: true,
  },
  {
    label: '优惠券数量',
    field: 'couponAmount',
    component: 'Input',
    colProps: {
      span: 11,
    },
    required: true,
  },
  {
    label: '优惠券类型',
    field: 'couponType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'coupon_type',
    },
    colProps: {
      span: 11,
    },
    required: true,
  },
  {
    label: '达到金额',
    field: 'useablePrice',
    component: 'InputNumber',
    colProps: {
      span: 11,
    },
    required: true,
  },
  {
    label: '达到数量',
    field: 'useableAmount',
    component: 'InputNumber',
    colProps: {
      span: 11,
    },
    required: true,
  },
  {
    label: '优惠金额',
    field: 'reduceAmount',
    component: 'InputNumber',
    colProps: {
      span: 11,
    },
    required: true,
  },
  {
    label: '折扣量',
    field: 'discount',
    component: 'InputNumber',
    componentProps: {
      suffix: '折',
    },
    colProps: {
      span: 11,
    },
    required: true,
  },
  {
    label: '折扣商品',
    field: 'discountProd',
    component: 'JSelectMultiple',
    componentProps: {
      dictCode: `uf_mall_goods,prod_name,id,sys_org_code='${orgCode}' AND del_flag = 0`,
    },
    required: true,
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'coupon_status',
    },
    required: true,
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  couponName: { title: '优惠券名称', order: 0, view: 'text', type: 'string' },
  couponAmount: { title: '优惠券数量', order: 1, view: 'text', type: 'string' },
  couponType: { title: '优惠券类型', order: 2, view: 'text', type: 'string' },
  useablePrice: { title: '达到金额', order: 3, view: 'number', type: 'number' },
  useableAmount: { title: '达到数量', order: 4, view: 'number', type: 'number' },
  reduceAmount: { title: '优惠金额', order: 5, view: 'number', type: 'number' },
  discount: { title: '折扣量', order: 6, view: 'number', type: 'number' },
  discountProd: { title: '折扣商品', order: 7, view: 'text', type: 'string' },
  status: { title: '状态', order: 8, view: 'number', type: 'number' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
